<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%@ include file="/include/service-base-header.jsp" %>
    <title>分销商管理</title>


</head>
<body>
<div class="wrapper">
    <jsp:include page="/include/left_menu.jsp">
        <jsp:param name="index" value="4"/>
    </jsp:include>
    <div class="main-panel">
        <nav class="navbar navbar-expand-lg navigation_shadow_none">
            <div class="container-fluid">
                <div class="navbar-wrapper b-navbar-wapper">
                    <a class="b-navbar-title-active" href="#">分销商管理</a>
                    <a class="b-navbar-title" href="${pageContext.request.contextPath}/s/sales-withdraw.do">佣金提现申请</a>
                </div>
                <div class="nav-collapse justify-content-end">
                    <div class="toolbar_left">
                        <div class="form-inline" style="height: 1rem">

                            <div class="form-group">
                                <div class="form-group" style="padding-bottom: 1.1rem;margin-left: 2rem">
                                    <input type="text" id="name_phone" class="form-control" placeholder="代理商账号"
                                           style="border:0px;border-bottom:#a8a8a8 1px solid;background: transparent">
                                </div>
                                <div class="btn btn-white btn-round btn-just-icon">
                                    <a class="btn btn-white btn-round btn-just-icon">
                                        <i class="material-icons" onclick="findSalesList()">search</i>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </nav>

        <div class="container-fluid">
            <div class="row" style="margin-left: 2rem;margin-top: 1rem">
                <div style="width: 18rem;">
                    <div class="card card-stats" style="width: 17rem;height: 8rem;">
                        <div class="card-header card-header-successtwo card-header-icon">
                            <div class="card-icon" style="background: #F1A342 100%">
                                <img src="../image/one.svg" style="width: 3rem;height: 3rem;padding: 0.5rem">
                            </div>
                            <p class="card-category" style="margin-right: 0.5rem;">二级代理商总佣金</p>
                            <h3 class="card-title" style="margin-right: 0.5rem;">
                                <span id="salesMoney"></span>
                                <small>KSH</small>
                            </h3>
                        </div>
                        <div class="card-footer">
                            <div class="stats" align="center">
                                <div>
                                    <img src="../image/set_icon.svg" style="width: 2rem;height: 2rem;padding: 0.3rem">
                                    <a href="${pageContext.request.contextPath}/s/sales-add.do" style="color:#5274EB;">新增代理商</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div style="width: 18rem;margin-left: 2rem">
                    <div class="card card-stats" style="width: 17rem;height: 8rem;">
                        <div class="card-header card-header-successtwo card-header-icon">
                            <div class="card-icon" style="background: #FF4081 100%">
                                <img src="../image/two.svg" style="width: 3rem;height: 3rem;padding: 0.5rem">
                            </div>
                            <p class="card-category" style="margin-right: 0.5rem;">二级代理商已提现佣金</p>
                            <h3 class="card-title" style="margin-right: 0.5rem;">
                                <span id="salesMoney_two"></span>
                                <small>KSH</small>
                            </h3>
                        </div>
                        <div class="card-footer">
                            <div class="stats" align="center">
                                <div>
                                    <img src="../image/set_icon.svg" style="width: 2rem;height: 2rem;padding: 0.3rem">
                                    <span onclick="" style="color:#555555;" id="num_count">二级代理商数:</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div style="width: 18rem;margin-left: 2rem">
                    <div class="card card-stats" style="width: 17rem;height: 8rem;">
                        <div class="card-header card-header-successtwo card-header-icon">
                            <div class="card-icon" style="background: #FF4081 100%">
                                <img src="../image/two.svg" style="width: 3rem;height: 3rem;padding: 0.5rem">
                            </div>
                            <p class="card-category" style="margin-right: 0.5rem;">二级代理商待提现佣金</p>
                            <h3 class="card-title" style="margin-right: 0.5rem;">
                                <span id="salesMoney_three"></span>
                                <small>KSH</small>
                            </h3>
                        </div>
                        <div class="card-footer">
                            <div class="stats" align="center">
                                <div>
                                    <img src="../image/one.svg" style="width: 2rem;height: 2rem;padding: 0.3rem">
                                    <span style="color:#5274EB;"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-12">
                    <div class="card card-plain">
                        <div class="card-header card-header-primary">
                            <div class="card-title">二级代理商列表</div>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table" id="table">
                                    <thead class=" text-primary">
                                    <tr>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            #
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            代理商姓名
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            电话号码
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            城市&地区
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            扩展会员
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            总佣金
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            已提现佣金
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            待提现佣金
                                        </th>
                                        <th style="color: #9c27b0;font-size: 1rem">
                                            操作
                                        </th>
                                    </tr>
                                    </thead>
                                    <tbody id="tb1">
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <nav aria-label="page">
                        <ul class="pagination justify-content-center" id="p1">
                        </ul>
                    </nav>
                </div>
            </div>
        </div>
    </div>
</div>

</body>


<script>
    var data_source;
    var page_count = 15;
    findSalesList();
    function findSalesList() {
        var data = {};
        var name_phone = $("#name_phone").val();
        data.salesPhone = name_phone;
        data.salesName = name_phone;
        $.ajax({
            url: baseUrl.base + baseUrl.sales + "/salesList",
            type: 'get',
            data: data,
            success: function (data) {
                if (data.code == "0") {
                    var res = data.results;

                    data_source = res.sales;

                    $("#num_count").html("二级代理商数：" + res.salesCount);
                    $("#salesMoney").html(res.salesMoney);
                    $("#salesMoney_two").html(res.outMoneyAll);
                    $("#salesMoney_three").html(res.inMoneyAll);


                    cutPagination(1);

                    // 配置分页
                    $("#p1").pagination({
                        totalData: res.length,
                        showData: page_count,
                        callback: function (idx) {
                            cutPagination(idx);
                        }
                    });
                } else {
                    var res = data.msg;
                    showNotification('bottom', 'right', res);
                }
            }
        });
    };

    /**
     * 分页
     * @param page 从1开始
     */
    function cutPagination(page) {

        var start = (page - 1) * page_count;
        var end = start + page_count;

        if (end > data_source.length) {
            end = data_source.length;
        }

        $("#tb1").empty();

        for (var i = start; i < end; i++) {
            var sales = data_source[i];

            var tr = document.createElement("tr");
            var td = document.createElement("td");
            var tdContent = document.createTextNode(i + 1);
            td.appendChild(tdContent);
            tr.appendChild(td);
            td = document.createElement("td");
            var name = document.createTextNode(sales.salesName);

            td.appendChild(name);
            tr.appendChild(td);

            td = document.createElement("td");
            tdContent = document.createTextNode(sales.salesPhone);
            td.appendChild(tdContent);
            tr.appendChild(td);

            td = document.createElement("td");
            tdContent = document.createTextNode(sales.salesCity + "&" + sales.salesArea);

            td.appendChild(tdContent);
            tr.appendChild(td);
            td = document.createElement("td");
            var span = document.createElement("span");
            tdContent = document.createTextNode(sales.userCount);
            span.appendChild(tdContent);
            var spandeta = document.createElement("span");
            spandeta.appendChild(tdContent);
            spandeta.style.marginLeft = '6px';
            td.appendChild(span);
            td.appendChild(spandeta);
            tr.appendChild(td);

            td = document.createElement("td");
            span = document.createElement("span");
            tdContent = document.createTextNode(sales.backMoney + "KSH");
            span.appendChild(tdContent);
            var spancash = document.createElement("span");
            spancash.appendChild(tdContent);
            spancash.style.marginLeft = '6px';
            td.appendChild(span);
            td.appendChild(spancash);
            tr.appendChild(td);

            td = document.createElement("td");
            tdContent = document.createTextNode(sales.outMoney + "KSH");
            td.appendChild(tdContent);
            tr.appendChild(td);

            td = document.createElement("td");
            tdContent = document.createTextNode(sales.salesMoney + "KSH");
            td.appendChild(tdContent);
            tr.appendChild(td);

            td = document.createElement("td");
            span = document.createElement("span");
            span.style.color = "#f44336";
            tdContent = document.createTextNode("明细");
            span.setAttribute("salesId", sales.salesId);
            span.onclick = function () {
                datils(this);
            };
            spancash.style.marginLeft = '6px';
            span.appendChild(tdContent);
            spancash.style.marginLeft = '6px';
            td.appendChild(span);
            tr.appendChild(td);


            document.getElementById("tb1").append(tr);
            document.getElementById("tb1").innerHTML;
        }
    }


    function datils(column) {
        var salesId = column.getAttribute("salesId");
        $(location).attr('href', '${pageContext.request.contextPath}/s/distribution-details.do?salesId=' + salesId);
    }
</script>

</html>